<?php

require('init.php');
$title = 'History Post';
require(LIBWWWDIR . '/header.php');

echo "<h1>Postmaratones</h1>\n\n";

// Get data. Starttime seems most logical sort criterion.
$res = query_contest($conn_db2, "1");

if( $res[0] == 0 ){
	echo "<p class=\"nodata\">No Postmaratones defined</p>\n\n";
}else{	
	$post_end = array();
	$now = now();
	for( $i=1; $i<=$res[0]; $i++ ){
		if( difftime($now,$res[$i]['endtime']) > 0 ){
			$post_end[]=$res[$i];
		}
	}

	if( count($post_end) == 0 ){
		echo "No Postmaratones finish Yed";
	}else{
		echo "<form action=\"problem_post.php\" method=\"post\">\n".
		"<table class=\"list sortable\">\n<thead>\n" .
	     	"<tr><th scope=\"col\">PID</th><th scope=\"col\">active</th>" .
	     	"<th scope=\"col\">starts</th><th scope=\"col\">ends</th>" .
	     	"<th scope=\"col\">freeze<br />scores</th>" .
	     	"<th scope=\"col\">unfreeze<br />scores</th>" .
	    	 "<th scope=\"col\">name</th></tr>\n</thead>\n<tbody>\n";
		
		for( $i=0; $i<count($post_end); $i++ )
		{
			$link = '<a href="problems_past.php?id=' . urlencode($post_end[$i]['cid']).'">';
			echo '<tr class="' .( $iseven ? 'roweven': 'rowodd' ) .
			(!$post_end[$i]['enabled']    ? ' disabled' :'') .
			($post_end[$i]['cid'] == $cid ? ' highlight':'') . '">' .
			"<td align=\"right\">" . $link .
			"c" . (int)$post_end[$i]['cid'] . "</a></td>\n" .
			"<td title=\"".htmlspecialchars(@$post_end[$i]['activatetime']) . "\">" .
			$link . printtime($post_end[$i]['activatetime']) . "</a></td>\n" .
			"<td title=\"" . htmlspecialchars($post_end[$i]['starttime']) . "\">" .
			$link . printtime($post_end[$i]['starttime'])."</a></td>\n".
			"<td title=\"".htmlspecialchars($post_end[$i]['endtime']) . "\">" .
			$link . printtime($post_end[$i]['endtime'])."</a></td>\n".
			"<td title=\"".htmlspecialchars(@$post_end[$i]['freezetime']) . "\">" .
			$link . ( isset($post_end[$i]['freezetime']) ?
			printtime($post_end[$i]['freezetime']) : '-' ) . "</a></td>\n" .
			"<td title=\"".htmlspecialchars(@$post_end[$i]['unfreezetime']) . "\">" .
			$link . ( isset($post_end[$i]['unfreezetime']) ?
			printtime($post_end[$i]['unfreezetime']) : '-' ) . "</a></td>\n" .
			"<td>" . $link . htmlspecialchars($post_end[$i]['contestname']) . "</a></td>\n";
			$iseven = ! $iseven;
			echo "</tr>\n";	
		}
		echo "</tbody>\n</table>\n</form>\n\n";
	}
}

require(LIBWWWDIR . '/footer.php');
